<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>jsRegExp</title>
    </head>
    <body>
        <script type="text/javascript">
            // 查找并原样输出
            var string = "Visit W3schools, w3schools, W3Schools , w3schoolsb";
            var part1 = /w3schools/gi;
            document.write( string.match( part1 ) );
            document.write( "<br />" );
            // test()返回true或false
            var part2 = new RegExp( "IS" );
            document.write( part2.test( "The best thing is no 1 Is" ) );
            document.write( "<br />" );
            // exec() 返回找到的值或null
            var part3 = new RegExp( "e" );
            document.write( part3.exec( "The best thing is free" ) );
            document.write( "<br />" );
            document.write( part3.exec( "abcdgag" ) );
            // compile()改变RegExp值
            part2.compile( "is" );
            document.write( "<br />" );
            document.write( part2.test( "The best thing is no 1 Is" ) );
            document.write( "<br />" );
            part3.compile( "d" );
            document.write( part3.exec( "abcdgag" ) );
            //
        </script>
    </body>
</html>
